/**
 * Created by 白雨浓 on 17-10-19 下午1:15.
 *
 * localStorage和sessionStorage工具
 */
const local = {
  setItem(k, v) {
    localStorage.setItem(k, JSON.stringify(v));
  },
  getItem(k) {
    const v = localStorage.getItem(k);
    if (v === null) return null;
    return JSON.parse(v);
  },
  removeItem(k) {
    const v = this.getItem(k);
    localStorage.removeItem(k);
    return v;
  },
  clear() {
    localStorage.clear();
  }
};

const session = {
  setItem(k, v) {
    sessionStorage.setItem(k, JSON.stringify(v));
  },
  getItem(k) {
    const v = sessionStorage.getItem(k);
    if (v === null) return null;
    return JSON.parse(v);
  },
  removeItem(k) {
    const v = this.getItem(k);
    sessionStorage.removeItem(k);
    return v;
  },
  clear() {
    sessionStorage.clear();
  }
};

export { local, session };


